package davey.wu.hamcrest.matcher;

import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

public class StringRegularMatcher extends TypeSafeMatcher<String> {
	private String regular;

	public StringRegularMatcher(String regular) {
		this.regular = regular;
	}

	@Override
	public boolean matchesSafely(String item) {
		return item.matches(this.regular);
	}

	public void describeTo(Description description) {
		description.appendText("a string must match the rugalar<" + this.regular + ">");
	}

	@Factory
	public static Matcher<String> regular(String regular) {
		return new StringRegularMatcher(regular);
	}
}
